﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ABCLogistic_System_V2._0.BL;
using ABCLogistic_System_V2._0.DA;

namespace ABCLogistic_System_V2._0.GUI
{
    public partial class frmMainInterface : Form
    {
        ABCLogisticsEntities context = new ABCLogisticsEntities();
        NHANVIEN nhanvien = new NHANVIEN();
        TAIKHOAN taikhoan = new TAIKHOAN();
        public frmMainInterface()
        {
            InitializeComponent();
        }

        string sHovaten;
        public frmMainInterface(string pHovatennhanvien)
        {
            sHovaten = pHovatennhanvien;
            InitializeComponent();
        }

        /// <summary>
        /// dong form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #region Di chuyen form
        // khai bao bien
        private bool dragging;
        private Point pointClick;

        /// <summary>
        /// xu ly khi nhap chuot vao form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmMainInterface_MouseDown(object sender, MouseEventArgs e)
        {
            this.Cursor = Cursors.Hand;
            if (e.Button == MouseButtons.Left)
            {
                dragging = true;
                pointClick = new Point(e.X, e.Y);
            }
            else
            {
                dragging = false;
            }
        }

        /// <summary>
        /// xu ly khi tha chuot ra
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmMainInterface_MouseUp(object sender, MouseEventArgs e)
        {
            dragging = false;
            this.Cursor = Cursors.Default;
        }

        /// <summary>
        /// xu ly khi di chuot nhap vao form va di chuyen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmMainInterface_MouseMove(object sender, MouseEventArgs e)
        {
            if (dragging == true)
            {
                Point pointMoveTo;
                pointMoveTo = this.PointToScreen(new Point(e.X, e.Y));
                pointMoveTo.Offset(-pointClick.X, -pointClick.Y);
                this.Location = pointMoveTo;
            }
        }
        #endregion

        #region Xu ly khi nhan cac button
        /// <summary>
        /// xu ly khi nhan nut quan tri he thong
        /// hien form quan tri he thong
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnQTHT_Click(object sender, EventArgs e)
        {
            frmQTHT quantrihethong = new frmQTHT();
            this.Hide();
            quantrihethong.Show();
        }
        #endregion

        private void frmMainInterface_Load(object sender, EventArgs e)
        {
            nhanvien = (from p in context.NHANVIENs
                        where p.MANV == sHovaten
                        select p).FirstOrDefault<NHANVIEN>();

            //taikhoan = context.TAIKHOANs.Where(p => p.NHANVIEN.MANV == sHovaten).FirstOrDefault();
            lkltenhanvien.Text = nhanvien.HOVATEN;
            //lkltenhanvien.Text = NV.hoten;
        }


    }
}
